package service;

import model.User_Friend;
import org.junit.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JDBCAddFriends {

    public void addFriend(User_Friend user_friend) {
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {
            connection = JDBCConnect.getConnection();
            String sql = "insert into user_friends values(?,?)";
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setInt(1, user_friend.getId());
            preparedStatement.setInt(2, user_friend.getFriendId());

            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JDBCTools.releaseDB(resultSet, preparedStatement, connection);
        }
    }
}
